#include <math.h>
#include "speed.h"
#include <stdio.h>
#include "main.h"


volatile uint32_t dropLastTime;
volatile float dropSpeed;
volatile uint32_t dropInterval;
volatile uint8_t DropSpeedMax = 120;
volatile uint8_t DropSpeedMin = 40;

// 最新一次遮挡时间 
uint32_t get_drop_last_time(void)
{
    return dropLastTime;
}

void set_drop_last_time(uint32_t data)
{
    dropLastTime = data;
}


// 滴速
float get_drop_speed(void)
{
    return dropSpeed;
}

void set_drop_speed(float data)
{
    dropSpeed = data;
}

// 滴的间隔
uint32_t get_drop_interval(void)
{
    return dropInterval;
}

void set_drop_interval(uint32_t data)
{
    dropInterval = data;
}

//滴速报警最大值
uint8_t get_drop_speed_max(void)
{
    return DropSpeedMax;
}

void set_drop_speed_max(uint8_t date)
{
    DropSpeedMax = date;
}


//滴速报警最小值
void set_drop_speed_min(uint8_t date)
{
    DropSpeedMin = date;
}

uint8_t get_drop_speed_min(void)
{
    return DropSpeedMin;
}

//void HAL_EXTI_Drop_Callback(uint16_t GPIO_Pin) {
//    if (HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_10) == GPIO_PIN_SET) {
//        HAL_Delay(50); // 简单消抖
//        if (HAL_GPIO_ReadPin(GPIOE, GPIO_PIN_10) == GPIO_PIN_SET) {
//            uint32_t currentTime = HAL_GetTick(); // 获取当前时间 

//                
//            
//            // 如果是第丿次测到水滴，只记录时间，不计算鿟度 
//            if (get_drop_last_time() != 0) {
//                set_drop_interval(currentTime - get_drop_last_time()); // 计算间隔 
//                
//                if (get_drop_interval() > 1000 && get_drop_interval() < 5000) { //过滤正常倿 
//                    set_drop_speed(60000.0f / (float)get_drop_interval()); // 滴鿿 = 60s / (Δt/1000) 
//                }
//            }
//         set_drop_last_time(currentTime);  // 更新时间 
//            
//        }
//    }
//}
